package com.example.iqiyitest.adapter;

import java.io.File;
import java.util.List;

import com.example.iqiyitest.R;
import com.example.iqiyitest.info.MovieDetailInfo;
import com.example.iqiyitest.utils.ImageLoader;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;



public class DaohangAdapter extends BaseAdapter {
	private List<String> list;
	private Context context;
	private OnMenuClickListener onClickListener;
	private int itemResource;
	private ImageLoader mImageLoader;
	private int lastFocus = 0;
	View rootView;
	ImageView iconImage;
	TextView appName;
	public DaohangAdapter(Context context, int itemResource, List<String> list, OnMenuClickListener onClickListener) {
		this.context = context;
		this.itemResource = itemResource;
		this.list = list;
		this.onClickListener = onClickListener;
		mImageLoader = ImageLoader.getInstance();// zhangzhl--后进先出法 ，优先加载 最后一个
	}
	
	public interface OnMenuClickListener {
		void onClick(int position, View v);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list==null?0:list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(context).inflate(itemResource, null);
		iconImage = (ImageView) view.findViewById(R.id.image_view);
		appName = (TextView) view.findViewById(R.id.name_text);
		appName.setText(list.get(position).toString());
		view.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Log.d("MyRecyclerView", "点击事件");
				if(onClickListener != null){
					onClickListener.onClick(position, v);
				} else{
				}
			}
		});
		return view;
	}
}
